package com.ymatou.iapi.sellercs.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellercs.parameter.UnfreezeRiskyUserBean;
import com.ymatou.iapi.sellercs.service.UnfreezeRiskyUserCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.YmtRiskyuser;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
/**
*解冻风险用户
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UnfreezeRiskyUser{
	private static UnfreezeRiskyUserBean unfreezeriskyuserBean;
	private static UnfreezeRiskyUserCall unfreezeriskyuserCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("解冻风险用户");
	}

	@Before
	public void caseUp() {
		unfreezeriskyuserBean=new UnfreezeRiskyUserBean();
		unfreezeriskyuserCall=new UnfreezeRiskyUserCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(unfreezeriskyuserCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UnfreezeRiskyUser_001() {
		Logger.start(true,"解冻风险用户,成功");
		try {
			Integer uid=1;
			List<YmtRiskyuser> list = YmtSellerCSIMWapper.selectYmtRiskyuserByUid(uid);
			if(list.size()==0){
				YmtSellerCSIMWapper.insertYmtRiskyuser(uid,true);
			}else if(!list.get(0).getDisabled()){
				YmtSellerCSIMWapper.updateYmtRiskyuserByUid(uid, true);
			}
			unfreezeriskyuserBean.setDisabled(false);
			unfreezeriskyuserBean.setUserId(uid);
			unfreezeriskyuserCall.setData(unfreezeriskyuserBean);
			unfreezeriskyuserCall.callService();			
			Logger.verifyIsContains("ok", unfreezeriskyuserCall.getReturnData(), "验证Status");
			list = YmtSellerCSIMWapper.selectYmtRiskyuserByUid(uid);
			Logger.verifyEquals(unfreezeriskyuserBean.getDisabled(), list.get(0).getDisabled(), "验证disable");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnfreezeRiskyUser_002() {
		Logger.start(true,"解冻再冻结风险用户,成功");
		try {
			Integer uid=1;
			List<YmtRiskyuser> list = YmtSellerCSIMWapper.selectYmtRiskyuserByUid(uid);
			if(list.size()==0){
				YmtSellerCSIMWapper.insertYmtRiskyuser(uid,true);
			}else if(!list.get(0).getDisabled()){
				YmtSellerCSIMWapper.updateYmtRiskyuserByUid(uid, true);
			}
			unfreezeriskyuserBean.setDisabled(false);
			unfreezeriskyuserBean.setUserId(uid);
			unfreezeriskyuserCall.setData(unfreezeriskyuserBean);
			unfreezeriskyuserCall.callService();			
			Logger.verifyIsContains("ok", unfreezeriskyuserCall.getReturnData(), "验证Status");
			list = YmtSellerCSIMWapper.selectYmtRiskyuserByUid(uid);
			Logger.verifyEquals(unfreezeriskyuserBean.getDisabled(), list.get(0).getDisabled(), "验证disable");
			
			unfreezeriskyuserBean.setDisabled(true);
			unfreezeriskyuserBean.setUserId(uid);
			unfreezeriskyuserCall.setData(unfreezeriskyuserBean);
			unfreezeriskyuserCall.callService();			
			Logger.verifyIsContains("ok", unfreezeriskyuserCall.getReturnData(), "验证Status");
			list = YmtSellerCSIMWapper.selectYmtRiskyuserByUid(uid);
			Logger.verifyEquals(unfreezeriskyuserBean.getDisabled(), list.get(0).getDisabled(), "验证disable");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_UnfreezeRiskyUser_003() {
		Logger.start(true,"原来没有风险数据,不操作");
		try {
			Integer uid=2;
			unfreezeriskyuserBean.setDisabled(false);
			unfreezeriskyuserBean.setUserId(uid);
			unfreezeriskyuserCall.setData(unfreezeriskyuserBean);
			unfreezeriskyuserCall.callService();			
			Logger.verifyIsContains("fail", unfreezeriskyuserCall.getReturnData(), "验证Status");
			List<YmtRiskyuser> list = YmtSellerCSIMWapper.selectYmtRiskyuserByUid(uid);
			Logger.verifyEquals(0, list.size(), "验证size");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}